/*
 * Copyright 2010-2012 Susanta Tewari. <freecode4susant@users.sourceforge.net>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/*
* ComGLHoodOView.java
*
* Created on November 15, 2007, 7:51 PM
 */
package gui.genomemap.view.outputView;

import genomemap.worker.LHood;

import gui.genomemap.event.event.WorkerOutputEvent;
import gui.genomemap.outputModel.ComPLHoodOModel;
import gui.genomemap.view.outputView.options.ComPLHoodOOptions;

import javautil.collections.ArrayUtil;
import javautil.io.IOUtil;

import java.text.DecimalFormat;

import javax.swing.JDialog;
import javax.swing.SwingUtilities;

/**
 *
 * @author  stewari1
 */
public class ComPLHoodOView extends OutputView {

    /** Field description */
    private final ComPLHoodOOptions optionsDialog = new ComPLHoodOOptions(new javax.swing.JFrame(),
                                                        true);


    // Variables declaration - do not modify//GEN-BEGIN:variables

    /** Field description */
    private javax.swing.JLabel jLabel1;

    /** Field description */
    private javax.swing.JLabel jLabel2;

    /** Field description */
    private javax.swing.JLabel lhood_JLabel;

    /** Field description */
    private javax.swing.JTextField probeSpacing_JTextField;


    // End of variables declaration//GEN-END:variables

    /** Creates new form ComGLHoodOView */
    public ComPLHoodOView() {

        initComponents();
        optionsDialog.setOutputView(this);
    }

    /**
     * This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */


    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1                 = new javax.swing.JLabel();
        lhood_JLabel            = new javax.swing.JLabel();
        probeSpacing_JTextField = new javax.swing.JTextField();
        jLabel2                 = new javax.swing.JLabel();

        jLabel1.setText("The Computed Physical Likelihood is :  ");
        jLabel2.setText("The Estimated Probe Spacings are: ");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);

        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(
                layout.createSequentialGroup().addContainerGap().addGroup(
                    layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(
                        layout.createSequentialGroup().addComponent(jLabel1).addPreferredGap(
                            javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(
                            lhood_JLabel)).addGroup(
                                layout.createSequentialGroup().addComponent(jLabel2).addGap(
                                    10, 10, 10).addComponent(
                                    probeSpacing_JTextField,
                                    javax.swing.GroupLayout.PREFERRED_SIZE, 177,
                                    javax.swing.GroupLayout.PREFERRED_SIZE))).addContainerGap(
                                        281, Short.MAX_VALUE)));
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(
                layout.createSequentialGroup().addContainerGap().addGroup(
                    layout.createParallelGroup(
                        javax.swing.GroupLayout.Alignment.BASELINE).addComponent(
                        jLabel1).addComponent(lhood_JLabel)).addPreferredGap(
                            javax.swing.LayoutStyle.ComponentPlacement.RELATED).addGroup(
                            layout.createParallelGroup(
                                javax.swing.GroupLayout.Alignment.BASELINE).addComponent(
                                jLabel2).addComponent(
                                probeSpacing_JTextField, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                javax.swing.GroupLayout.PREFERRED_SIZE)).addGap(57, 57, 57)));

    }    // </editor-fold>//GEN-END:initComponents

    @Override
    public void refresh() {

        if (getOutputModel() == null) {

            lhood_JLabel.setText("");

            return;
        }

        ComPLHoodOModel comPLHoodOModel = (ComPLHoodOModel) getOutputModel();

        lhood_JLabel.setText("" + comPLHoodOModel.getLHood());
        probeSpacing_JTextField.setText(
            IOUtil.toString(
                ArrayUtil.getDoubleArray(comPLHoodOModel.getProbeSpacing()), ",",
                new DecimalFormat("0.####")));
        optionsDialog.setOptions(comPLHoodOModel);
    }

    @Override
    public JDialog getOptionsDialog() {
        return optionsDialog;
    }

    public void doComPLHoodOutput(WorkerOutputEvent e) {


        // the view(OutputView) is listening from the working process now
        // launch runnables on swing thread according to the runtime display options set
        // in your output model which is the same instance the process worker has.
        // ontain information on the worker using e.getSource().. this case it will be an LHood object
        LHood lhood = (LHood) e.getSource();


        // update according to the options set
        Runnable runnable = new Runnable() {
            public void run() {}
        };

        SwingUtilities.invokeLater(runnable);
    }
}
